package com.yunhe.abnormal.consts;

import com.yunhe.common.constant.CacheConsts;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 异常规则实例缓存Key常量类
 * @author liuronglei
 */
public class AlarmRuleInstanceKey {
    /**
     * 通用key定义
     */
    private static String getKey(Long id,
                                 Long stationId,
                                 Long deviceId,
                                 Long stationCode,
                                 Long stationIdOf) {
        List<String> keyList = new ArrayList<>();
        if (id != null) {
            keyList.add("id" + CacheConsts.SPLIT_FIELD + id);
        }
        if (stationId != null) {
            keyList.add("s" + CacheConsts.SPLIT_FIELD + stationId);
        }
        if (deviceId != null) {
            keyList.add("d" + CacheConsts.SPLIT_FIELD + deviceId);
        }
        if (stationCode != null) {
            keyList.add("sc" + CacheConsts.SPLIT_FIELD + stationCode);
        }
        if (stationIdOf != null) {
            keyList.add("so" + CacheConsts.SPLIT_FIELD + stationIdOf);
        }
        return StringUtils.join(keyList.toArray(), CacheConsts.SPLIT_TYPE);
    }

    public static String getIdKey(Long id) {
        return getKey(id, null, null, null, null);
    }

    public static String getStationIdKey(Long stationId) {
        return getKey(null, stationId, null, null, null);
    }

    public static String getDeviceIdKey(Long deviceId) {
        return getKey(null, null, deviceId, null, null);
    }

    public static String getStationOfKey(Long stationIdOf, Long stationCode) {
        return getKey(null, null, null, stationCode, stationIdOf);
    }
}
